package com.ruoyi.front;

import cn.hutool.core.date.DateTime;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.seg.Segment;
import com.hankcs.hanlp.seg.common.Term;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysMember;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.utils.*;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.param.ParamDoc;
import com.ruoyi.system.response.TopicDoc;
import com.ruoyi.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.server.DelegatingServerHttpResponse;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

@Controller
public class topic extends footcontroller {
    @Autowired
    private ISysDocService iSysDocService;
    @Autowired
    private ISysTradesetService iSysTradesetService;
    @Autowired
    private ISysGlodpotService iSysGlodpotService;
    @Autowired
    private  ISysMemberService iSysMemberService;
    @Autowired
    private  ISysTopicService iSysTopicService;
    @Autowired
    private ISysTopicTypeService iSysTopicTypeService;
    @Autowired
    private ISysGroupService iSysGroupService;
    @Autowired
    private ISysVgroupService iSysVgroupService;
    @Autowired
    private  ISysTopicCommentService iSysTopicCommentService;
    @Autowired
    private  ISysTopicDownlogService iSysTopicDownlogService;
    @Autowired
    private  ISysTopicFavoriteService iSysTopicFavoriteService;
    @Autowired
    private  ISysReportItemService iSysReportItemService;
    @Autowired
    private ISysReportService iSysReportService;
    @Autowired
    private ISysOsssetService sysOsssetService;
    @GetMapping({"/topic.html"})
    public String topic(ModelMap modelMap,@RequestParam(value = "tid",defaultValue = "0") Integer tid,@RequestParam(value = "key",defaultValue = "") String key)
    {

        List<SysTopic> sysTopicList = iSysTopicService.selectTopicByTypeid(tid,key);
        //TableSupport.buildPageRequest().setPageSize(2);
        startPage();
        for (int i = 0;i<sysTopicList.size();i++)
        {
            sysTopicList.get(i).setKeyword(new SimpleDateFormat("yyyy-MM-dd").format(new Date(sysTopicList.get(i).getInsertdate().getTime())));
        }
        modelMap.put("topic_array",sysTopicList);
        List<SysTopicType> sysTopicTypeList = iSysTopicTypeService.selectSysTopicTypeList(new SysTopicType());
        modelMap.put("topic_type_array",sysTopicTypeList);
        List<SysTradeset> sysTradesets = iSysTradesetService.selectSysTradesetList(new SysTradeset());
        modelMap.put("systradesets",sysTradesets.get(0));
        //专题作者信息
        Boolean istopic = false;
        if(ShiroUtils.getSysMember()!=null) {
            SysMember sysMember = iSysMemberService.selectSysMemberByUserid(ShiroUtils.getSysMember().getUserid());
            SysGroup sysGroup = iSysGroupService.selectSysGroupByGroupid(sysMember.getGroupid());
            istopic = StringUtils.contains(sysGroup.getRights(), "42");
        }

        modelMap.put("pagesize",10);
        modelMap.put("cpage",TableSupport.buildPageRequest().getPageNum());
        modelMap.put("total",sysTopicList.size());
        modelMap.put("topic",istopic);
        modelMap.put("tid",tid);
        modelMap.put("navurl",getRequest().getRequestURI());
        modelMap.put("key",key);
        getabout(modelMap);
        return "topic/topic";
    }
    @GetMapping({"pub.html"})
    public String pubtopic(ModelMap modelMap,@RequestParam(value = "topicid",defaultValue = "0") Long topicid)
    {
        List<SysTopicType> sysTopicTypeList = iSysTopicTypeService.selectSysTopicTypeList(new SysTopicType());
        SysTopic topic = new SysTopic();
        modelMap.put("topic_type_array",sysTopicTypeList);
        List<SysTradeset> sysTradesets = iSysTradesetService.selectSysTradesetList(new SysTradeset());
        modelMap.put("systradesets",sysTradesets.get(0));
        SysMember sysMember = iSysMemberService.selectSysMemberByUserid(ShiroUtils.getSysMember().getUserid());
        SysGroup sysGroup = iSysGroupService.selectSysGroupByGroupid(sysMember.getGroupid());
        Boolean ispreview = StringUtils.contains(sysGroup.getRights(),"43");
        modelMap.put("ispreview",ispreview);
        modelMap.put("topicid",topicid);
        if((topicid>0)&&((topic = iSysTopicService.selectSysTopicByTopicid(topicid))!=null))
        {
            if(topic.getUserid()!=ShiroUtils.getSysMember().getUserid())
            {
                getabout(modelMap);
                return "topic/tip";
            }
            else
            {
                modelMap.put("topic", topic);
                getabout(modelMap);
                return "topic/topic_pub";

            }
        }
        else
        {
            modelMap.put("topic", topic);
            getabout(modelMap);
            return "topic/topic_pub";
        }


    }
    @PostMapping({"pub.html"})
    @ResponseBody
    public Integer pubtopic1(SysTopic sysTopic) throws IOException {
        List<String> listdocids = Arrays.asList(sysTopic.getDocs().split(","));
        TopicDoc topicDoc = iSysDocService.selectByIdsSel(listdocids);
        if(sysTopic.getDownpay()==null)
        {
            if(sysTopic.getDiscount()==null)
            {
                sysTopic.setDownpay(Float.parseFloat(new DecimalFormat("#.##").format(topicDoc.getTotalpay())));
            }
            else
            {
                sysTopic.setDownpay(Float.parseFloat(new DecimalFormat("#.##").format(topicDoc.getTotalpay()*sysTopic.getDiscount())));
            }

        }
        sysTopic.setTotalpay(topicDoc.getTotalpay());
        sysTopic.setSize(topicDoc.getSize().longValue());
        sysTopic.setDocnum(topicDoc.getDocnum().longValue());
        sysTopic.setWord(sysTopic.getWord().replaceAll("(^,|,$)", ""));
        sysTopic.setUserid(ShiroUtils.getSysMember().getUserid());
        //上传专题封面
        // 上传文件路径
        if(sysTopic.getFile()!=null&&sysTopic.getFile().getSize()>0) {
            String filePath = RuoYiConfig.getUploadPath();
            String fileName = FileUploadUtils.upload(filePath, sysTopic.getFile());
            sysTopic.setCover(fileName);
        }
      if(sysTopic.getTopicid()!=null && sysTopic.getTopicid()>0)
      {
         iSysTopicService.updateSysTopic(sysTopic);

      }
      else {
          iSysTopicService.insertSysTopic(sysTopic);

      }
        return sysTopic.getTopicid().intValue();
    }
    @GetMapping({"select.html"})
    public String select(ModelMap modelMap)
    {
        return "topic/topic_select.html";

    }
    @PostMapping({"select.html"})
    @ResponseBody
    public TableDataInfo select1(@RequestParam("searchcol") String searchcol, @RequestParam("searchtext") String searchtext, @RequestParam("sortcol") String sortcol, @RequestParam("sorttext") String sorttext)
    {
        SysMember sysMember = iSysMemberService.selectSysMemberByUserid(ShiroUtils.getSysMember().getUserid());
        SysGroup sysGroup = iSysGroupService.selectSysGroupByGroupid(sysMember.getGroupid());
        Boolean issystem = StringUtils.contains(sysGroup.getRights(),"3");
        Boolean isconfig = StringUtils.contains(sysGroup.getRights(),"4");
        Long userid = 0l;
        if(!issystem || !isconfig)
            userid = ShiroUtils.getSysMember().getUserid();
        List<SysDoc> sysDocList = iSysDocService.searchSysDocList(userid,searchcol,searchtext,sortcol,sorttext);
        startPage();
         return getDataTable(sysDocList);

    }
    @GetMapping({"getdoc.html"})
    @ResponseBody
    public AjaxResult getdoc(@RequestParam("docid") Long docid)
    {
        SysMember sysMember = iSysMemberService.selectSysMemberByUserid(ShiroUtils.getSysMember().getUserid());
        SysGroup sysGroup = iSysGroupService.selectSysGroupByGroupid(sysMember.getGroupid());
        Boolean issystem = StringUtils.contains(sysGroup.getRights(),"3");
        Boolean isconfig = StringUtils.contains(sysGroup.getRights(),"4");
        SysDoc sysDoc = iSysDocService.selectSysDocByDocid(docid);
        Boolean isself = sysDoc.getUserid()==ShiroUtils.getSysMember().getUserid();
        if ((sysDoc!=null)&&(issystem||isconfig||isself))
            return AjaxResult.success(sysDoc);
        else
            return AjaxResult.success(-1);
    }
    @GetMapping({"/fenci/{keyword}"})
    @ResponseBody
    public String fenci(@PathVariable("keyword") String keyword)
    {
        return UnzipAndListFilesUtils.fenci(keyword);
    }
    //浏览专题
    @GetMapping({"/topic/{topicid}"})
    public String topicview(ModelMap modelMap,@PathVariable("topicid") Long topicid)
    {
        SysTopic sysTopic = iSysTopicService.selectSysTopicByTopicid1(topicid);
        //专题作者
        SysMember sysMember = iSysMemberService.selectSysMemberByUserid(sysTopic.getUserid());
        //SysMember sysMember = iSysMemberService.selectSysMemberByUserid(ShiroUtils.getSysMember().getUserid());
        modelMap.put("user",sysMember);
        List<SysTradeset> sysTradesets = iSysTradesetService.selectSysTradesetList(new SysTradeset());
        if(sysTopic!=null) {
            //专题类型
            SysTopicType sysTopicType = new SysTopicType();
            sysTopicType.setState(1);
            List<SysTopicType> sysTopicTypeList = iSysTopicTypeService.selectSysTopicTypeList(sysTopicType);
            //专题相关文档
            List<String> listdocids = Arrays.asList(sysTopic.getDocs().split(","));
            List<SysDoc> sysDocList = iSysDocService.selectByDocIds(listdocids);
            modelMap.put("docs",sysDocList);
            //end
            SysMember sysMember1 = new SysMember();
            if(ShiroUtils.getSubject().getPrincipal() != null) {
                sysMember1 =  ShiroUtils.getSysMember();

            }
            else
            {
                sysMember1.setUserid(-1l);
                sysMember1.setUsername("游客");
                sysMember1.setNickname("");
                //sysMember1.setGlods(0l);
                sysMember1.setGroupid(0l);
                sysMember1.setVgroupid(0l);
            }
            modelMap.put("member",sysMember1);
            sysTopic.setDownpay2(sysTopic.getDownpay());
            if(sysTopic.getUserid()==sysMember1.getUserid()) //自己的专题
            {
                sysTopic.setDownpay2(0f);
            }
            else
            {
                Long paydue = sysTradesets.get(0).getPaydue();
                List<Long> typeids = Arrays.asList(-50L, -51L, -52L);
                SysGlodpot sysGlodpot = iSysGlodpotService.findTypeUseridLinkedDue(typeids, sysMember1.getUserid(), sysTopic.getTopicid(),paydue);
                if(sysGlodpot!=null)
                {
                    sysTopic.setDownpay2(0f);
                }
                else
                {
                    SysVgroup sysVgroup = iSysVgroupService.selectSysVgroupByVgroupid(sysMember1.getVgroupid());
                    if((sysVgroup!=null) && (sysMember1.getVipdate()!=null) /*&&(vipdateTime.isBefore(currentDateTime))*/)
                    {
                        LocalDateTime currentDateTime = LocalDateTime.now();
                        String dateTimeString = sysMember1.getVipdate().toString();
                        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                        //LocalDateTime vipdateTime = LocalDateTime.parse(dateTimeString, formatter);
                        LocalDateTime vipdateTime = LocalDateTime.ofInstant(sysMember1.getVipdate().toInstant(), ZoneId.systemDefault());
                        if(vipdateTime.isBefore(currentDateTime))
                            sysTopic.setDownpay2(sysTopic.getDownpay()*(sysTopic.getIsvip()>0?0:sysVgroup.getDiscount()));
                    }

                }
            }
            modelMap.put("topic",sysTopic);
            //专题评论
            SysTopicComment sysTopicComment = new SysTopicComment();
            sysTopicComment.setState(1);
            sysTopicComment.setTopicid(sysTopic.getTopicid());
            List<SysTopicComment> sysTopicCommentList2 = iSysTopicCommentService.selectSysTopicCommentList1(sysTopicComment);
            startPage();
            List<SysTopicComment> sysTopicCommentList = iSysTopicCommentService.selectSysTopicCommentList1(sysTopicComment);
            for (int i=0;i<sysTopicCommentList.size();i++)
            {

                if(sysTopicCommentList.get(i).getPcommentid()!=null) {
                    SysTopicComment sysTopicComment1 = new SysTopicComment();
                    sysTopicComment1.setCommentid(sysTopicCommentList.get(i).getPcommentid());
                    List<SysTopicComment> sysTopicCommentList1 = iSysTopicCommentService.selectSysTopicCommentList(sysTopicComment1);
                    if (sysTopicCommentList1.size() > 0)
                        sysTopicCommentList.get(i).setSysTopicComment(sysTopicCommentList1.get(0));
                    else
                        sysTopicCommentList.get(i).setSysTopicComment(null);
                }
                //删除按钮
                String submitulr = "{url:'/topic/reply-del.html?commentid="+sysTopicCommentList.get(i).getCommentid()+"',tip:'删除评论?',back:['删除成功', '您无权限删除']}";
                //modelMap.put("submiturl",submitulr);
                sysTopicCommentList.get(i).setNote(submitulr);
                //举报按钮
                String report = "{title:'举报',body:'/topic/report.html?commentid="+sysTopicCommentList.get(i).getCommentid()+"',back:['举报成功', '举报失败']}";
                sysTopicCommentList.get(i).setReport(report);
            }

            modelMap.put("pagesize",10);
            modelMap.put("cpage",TableSupport.buildPageRequest().getPageNum());
            modelMap.put("total",sysTopicCommentList2.size());
            modelMap.put("comments",sysTopicCommentList);
            //下载记录
            SysTopicDownlog sysTopicDownlog = new SysTopicDownlog();
            sysTopicDownlog.setTopicid(sysTopic.getTopicid());
            List<SysTopicDownlog> sysTopicDownlogList = iSysTopicDownlogService.selectSysDownlogListleftjoin(sysTopicDownlog);
            modelMap.put("downlogs",sysTopicDownlogList);
            //点赞
            SysTopicFavorite sysTopicFavorite = new SysTopicFavorite();
            sysTopicFavorite.setTopicid(sysTopic.getTopicid());
            sysTopicFavorite.setUserid(sysMember1.getUserid());
            List<SysTopicFavorite> sysTopicFavoriteList = iSysTopicFavoriteService.selectSysTopicFavoriteList(sysTopicFavorite);
            Boolean fav_state = false;
            if(sysTopicFavoriteList.size()>0)
                fav_state = true;
            modelMap.put("fav_state",fav_state);
            modelMap.put("types", sysTopicTypeList);
            modelMap.put("systradesets", sysTradesets.get(0));
            SysGroup sysGroup = iSysGroupService.selectSysGroupByGroupid(sysMember1.getGroupid());
            //是否有权删除评论和是否自己所评
            Boolean iscommentdel = false;
            if(StringUtils.contains(sysGroup.getRights(), "49"))
                iscommentdel = true;
            modelMap.put("iscommentdel", iscommentdel);
            //是否有编辑权限
            Boolean iscommentedit = false;
            if(StringUtils.contains(sysGroup.getRights(), "48"))
                iscommentedit = true;
            modelMap.put("iscommentedit", iscommentedit);
            //是否有评论权限
            Boolean iscommentadd = false;
            if(StringUtils.contains(sysGroup.getRights(), "46"))
                iscommentadd = true;
            modelMap.put("submiturl","{url:'/topic/reply-del.html?commentid=[(${comment.commentid})]',tip:'删除评论?',back:['删除成功', '您无权限删除']}");
            modelMap.put("iscommentadd", iscommentadd);
            getabout(modelMap);
            return "topic/topic_view";
        }
        else
        {
            String message = "您预览的专题不存在";
            modelMap.put("message",message);
            getabout(modelMap);
            return "topic/tip.html";
        }
    }
    @GetMapping({"/topic/favorite/{topicid}"})
    @ResponseBody
    public Integer favorite(@PathVariable("topicid") Long topicid )
    {
        if(ShiroUtils.getSubject().getPrincipal() == null)
            return  -1;

         SysTopicFavorite sysTopicFavorite = new SysTopicFavorite();
         sysTopicFavorite.setUserid(ShiroUtils.getSysMember().getUserid());
         sysTopicFavorite.setTopicid(topicid);
         List<SysTopicFavorite> sysTopicFavoriteList = iSysTopicFavoriteService.selectSysTopicFavoriteList(sysTopicFavorite);
         if(sysTopicFavoriteList.size()>0)
             iSysTopicFavoriteService.deleteSysTopicFavoriteByFavid(sysTopicFavoriteList.get(0).getFavid());
         else
             iSysTopicFavoriteService.insertSysTopicFavorite(sysTopicFavorite);

         return  1;
    }
    @GetMapping(value = {"/downtopic.htm"})
    public ResponseEntity<ByteArrayResource> downtopic(@RequestParam("topicid") long topicid) throws IOException {
        SysTopic sysTopic = iSysTopicService.selectSysTopicByTopicid(topicid);
        SysMember sysMember = iSysMemberService.selectSysMemberByUserid(ShiroUtils.getSysMember().getUserid());
        //新增下载次数
        iSysTopicService.increaseDowncount(topicid);
        //新增下载记录
        SysTopicDownlog sysDownlog = new SysTopicDownlog();
        sysDownlog.setUserid(ShiroUtils.getSysMember().getUserid());
        sysDownlog.setTopicid(topicid);
        List<SysTopicDownlog> sysDownlogList = iSysTopicDownlogService.selectSysTopicDownlogList(sysDownlog);
        if (sysDownlogList.size()>0)
        {
           iSysTopicDownlogService.increaseDowncount(sysDownlogList.get(0).getLogid());

        }
        else
        {

            iSysTopicDownlogService.insertSysTopicDownlog(sysDownlog);

        }
        //结束
        //阿里云配置
        SysOssset sysOssset;
        sysOssset = sysOsssetService.selectSysOsssetList(new SysOssset()).get(0);
        //OSS ossClient = new OSSClientBuilder().build(sysOssset.getEndpoint(), sysOssset.getKeyid(), sysOssset.getKeysecret());
        List<String> listdocids = Arrays.asList(sysTopic.getDocs().split(","));
        List<SysDoc> sysDocList = iSysDocService.selectByDocIds(listdocids);
        List<ParamUpload> paramDocList = new ArrayList<>();
        for(int i=0;i<sysDocList.size();i++) {
            ParamUpload paramDoc = new ParamUpload();
            String docpath = sysDocList.get(i).getPath();
            String pre = Constants.RESOURCE_PREFIX;
            String dirname = RuoYiConfig.getProfile();
            String aliyun_src = docpath.replace(pre+"/","");
            String srcurl = dirname + docpath.replace(pre, "");
            String soucename = sysDocList.get(i).getTitle() + "." + sysDocList.get(i).getExten();
            for (ParamUpload paramUpload : paramDocList)
            {
                if(paramUpload.getTitle().equals(soucename))
                    soucename = sysDocList.get(i).getTitle() +"-"+UUID.randomUUID()+"." + sysDocList.get(i).getExten();

            }
            if(sysOssset.getState()>0&&ossFileExist(aliyun_src)) {
                srcurl = aliyun_src;
            }
            paramDoc.setPath(srcurl);
            paramDoc.setTitle(soucename);
            paramDocList.add(paramDoc);
        }
        String topfilename = sysTopic.getTitle()+".zip";
        String zipfile = RuoYiConfig.getDownloadPath()+sysTopic.getTitle()+".zip";
        if (sysOssset.getState()>0)
            UnzipAndListFilesUtils.zipFiles(zipfile,paramDocList,sysOssset.getEndpoint(),sysOssset.getKeyid(),sysOssset.getKeysecret(),sysOssset.getBucket());
        else
            UnzipAndListFilesUtils.zipFiles(zipfile,paramDocList);
        byte[] bytes = Files.readAllBytes(new File(zipfile).toPath());

        ByteArrayResource bar = new ByteArrayResource(bytes);
        return ResponseEntity.ok()
                .contentType(MediaType.APPLICATION_OCTET_STREAM)
                .header("Content-disposition", "attachment; filename=\"" + URLEncoder.encode(topfilename) + "\";charset=utf-8")
                .body(bar);

    }
    //专题评论
    @PostMapping({"/topic/comment"})
    @ResponseBody
    public Integer topiccomment(SysTopicComment sysTopicComment)  {
        SysMember sysMember = iSysMemberService.selectSysMemberByUserid(ShiroUtils.getSysMember().getUserid());
        SysGroup sysGroup = iSysGroupService.selectSysGroupByGroupid(sysMember.getGroupid());
        if(StringUtils.contains(sysGroup.getRights(),"46"))
        {
            sysTopicComment.setUserid(ShiroUtils.getSysMember().getUserid());
            sysTopicComment.setState(1);
            iSysTopicCommentService.insertSysTopicComment(sysTopicComment);
            return sysTopicComment.getCommentid().intValue();
        }
        else
        {
            return -1;
        }
    }
    //评论编辑
    @GetMapping ({"/topic/commentedit.html"})
    public String topiccommentedit(ModelMap modelMap,@RequestParam("commentid") long commentid)  {
        SysMember sysMember = iSysMemberService.selectSysMemberByUserid(ShiroUtils.getSysMember().getUserid());
        SysGroup sysGroup = iSysGroupService.selectSysGroupByGroupid(sysMember.getGroupid());
        SysTopicComment sysTopicComment = new SysTopicComment();
        sysTopicComment.setCommentid(commentid);
        sysTopicComment.setUserid(ShiroUtils.getSysMember().getUserid());
        List<SysTopicComment> sysTopicCommentList = iSysTopicCommentService.selectSysTopicCommentList(sysTopicComment);
        if(sysTopicCommentList.size()>0)
        {
            modelMap.put("comment",sysTopicCommentList.get(0));
            SysTopic sysTopic = iSysTopicService.selectSysTopicByTopicid(sysTopicCommentList.get(0).getTopicid());
            modelMap.put("topic_title",sysTopic.getTitle());


        }
        getabout(modelMap);
        return "topic/topic_reply_edit";
    }
    @PostMapping({"/topic/editcommentadd"})
    @ResponseBody
    public Integer editcommentadd(SysTopicComment sysTopicComment)  {
        SysMember sysMember = iSysMemberService.selectSysMemberByUserid(ShiroUtils.getSysMember().getUserid());
        SysGroup sysGroup = iSysGroupService.selectSysGroupByGroupid(sysMember.getGroupid());
        if(StringUtils.contains(sysGroup.getRights(),"48"))
        {
            iSysTopicCommentService.updateSysTopicComment(sysTopicComment);
            return sysTopicComment.getCommentid().intValue();
        }
        else
        {
            return -1;
        }
    }
    //回复添加
    @GetMapping ({"/topic/replyadd.html"})
    public String replyadd(ModelMap modelMap,@RequestParam("commentid") long commentid)  {
        SysMember sysMember = iSysMemberService.selectSysMemberByUserid(ShiroUtils.getSysMember().getUserid());
        SysGroup sysGroup = iSysGroupService.selectSysGroupByGroupid(sysMember.getGroupid());
        SysTopicComment sysTopicComment = new SysTopicComment();
        sysTopicComment.setCommentid(commentid);
        List<SysTopicComment> sysTopicCommentList = iSysTopicCommentService.selectSysTopicCommentList(sysTopicComment);
        if(sysTopicCommentList.size()>0)
        {
            modelMap.put("comment",sysTopicCommentList.get(0));
            SysTopic sysTopic = iSysTopicService.selectSysTopicByTopicid(sysTopicCommentList.get(0).getTopicid());
            modelMap.put("topic_title",sysTopic.getTitle());


        }
        getabout(modelMap);
        return "topic/topic_reply_reply";
    }
    @PostMapping({"/topic/replycommentadd"})
    @ResponseBody
    public Integer replycommentadd(SysTopicComment sysTopicComment)  {
        SysMember sysMember = iSysMemberService.selectSysMemberByUserid(ShiroUtils.getSysMember().getUserid());
        SysGroup sysGroup = iSysGroupService.selectSysGroupByGroupid(sysMember.getGroupid());
        if(StringUtils.contains(sysGroup.getRights(),"48"))
        {
            sysTopicComment.setUserid(ShiroUtils.getSysMember().getUserid());
            sysTopicComment.setState(1);
            sysTopicComment.setPcommentid(sysTopicComment.getCommentid());
            iSysTopicCommentService.insertSysTopicComment(sysTopicComment);
            return sysTopicComment.getCommentid().intValue();
        }
        else
        {
            return -1;
        }
        //评论删除
    }
    @PostMapping({"/topic/reply-del.html"})
    @ResponseBody
    public Integer replydel(@RequestParam("commentid") long commentid)  {
        SysMember sysMember = iSysMemberService.selectSysMemberByUserid(ShiroUtils.getSysMember().getUserid());
        SysGroup sysGroup = iSysGroupService.selectSysGroupByGroupid(sysMember.getGroupid());
        if(StringUtils.contains(sysGroup.getRights(),"49"))
        {
            return  iSysTopicCommentService.deleteSysTopicCommentByCommentid(commentid);
        }
        else
        {
            return -1;
        }
    }
    //举报
    @GetMapping ({"/topic/report.html"})
    public String report(ModelMap modelMap,@RequestParam("commentid") long commentid)  {
        SysReportItem sysReportItem = new SysReportItem();
        sysReportItem.setState(1);
        List<SysReportItem> sysReportItemList = iSysReportItemService.selectSysReportItemList(sysReportItem);
        SysReport sysReport = new SysReport();
        sysReport.setDocid(commentid);
        sysReport.setUserid(ShiroUtils.getSysMember().getUserid());
        List<SysReport> sysReportList = iSysReportService.selectSysReportList(sysReport);
        if(sysReportList.size()>0)
            sysReport = sysReportList.get(0);
        else
        {
            sysReport.setReportid(0l);
            sysReport.setReport(sysReportItemList.get(0).getTitle());

        }
        modelMap.put("report_item",sysReportItemList);
        modelMap.put("report",sysReport);
        modelMap.put("docid",commentid);
        return "topic/report";

    }
    @PostMapping  ({"/topic/report.html"})
    @ResponseBody
    public Integer report(SysReport sysReport)  {
            sysReport.setUserid(ShiroUtils.getSysMember().getUserid());
            return  iSysReportService.insertSysReport(sysReport);

    }
}